import React from 'react';
import { connect } from 'dva';
import styles from './Teachers.css';
import TeacherList from '../components/TeacherList';
import TeacherModal from '../components/teacher/TeacherModal';
import {Row,Col,Button} from 'antd';
function Teachers({dispatch,teacher}) {
    let {modal} = teacher;
    return (
	      <Row>
        <Col style={{ textAlign: 'right' }}><Button type='primary' onClick={()=>{
            dispatch({type:'teacher/showModal'});
        }}>创建教师</Button></Col>
            <Col><TeacherList {...teacher}
            onModify={(record)=>{
                dispatch({type:'teacher/startModify',payload:record})
            }}
            onDelete={(id)=>{
                dispatch({type:'teacher/delete',payload:id})
            }}/></Col>
            <Col><TeacherModal
        visible={modal.show}
        onOk={(data)=>{
            if(modal.modify){
                dispatch({type:'teacher/modify',payload:data})
            }else{
                dispatch({type:'teacher/create',payload:data})
            }
        }}
        onCancel={()=>{
            dispatch({type:'teacher/hideModal'});
        }}
        type={modal.modify?false:true}
        loading={modal.loading}
        item={modal.modify}
            /></Col>
        </Row>
    );
}

function mapStateToProps({teacher}) {
  return {teacher};
}

export default connect(mapStateToProps)(Teachers);
